/**
 * @author hAmmeRoL, created: 2008-7-10
 * SJTU
 */

package gui;

import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QKeyEvent;
import com.trolltech.qt.gui.QTextEdit;
import com.trolltech.qt.gui.QWidget;

/**
 * Class used in the chat window to edit text
 * 
 * @author hAmmeRoL
 * 
 */
public class ChatTextEdit extends QTextEdit {

	/**
	 * Signal indicating that the user has pressed return and ready to send a
	 * message
	 */
	public Signal1<String> messageReady = new Signal1<String>();

	/**
	 * Override keyPressEvent and process key event
	 */
	protected void keyPressEvent(QKeyEvent arg__1) {
		// return pressed, ready to send message
		if (arg__1.key() == Qt.Key.Key_Return.value()) {
			messageReady.emit(this.toPlainText());
			// clear text field
			this.clear();
		} else {
			super.keyPressEvent(arg__1);
		}
	}

	public ChatTextEdit(QWidget parent) {
		super(parent);
	}

}

